<template>
  <view class="activity-detail-card">
    <!-- 活动图片由外部传入，不在此组件内渲染 -->
    <view class="activity-title">{{ info.activityName }}</view>
    <view class="activity-publish">活动发布时间：{{ info.createTime }}</view>
    <view class="activity-info-card">
      <view class="info-row">
        <image
          class="info-icon"
          src="/static/icon/date_icon.png"
        />
        <text class="info-label">活动时间：</text>
        <text class="info-value">{{
          info.activityStartTime + ' ~ ' + info.activityEndTime
        }}</text>
      </view>
      <view class="info-row">
        <image
          class="info-icon"
          src="/static/icon/map_icon.png"
        />
        <text class="info-label">活动地址：</text>
        <text class="info-value">{{ info.activityLocation }}</text>
      </view>
      <view class="info-row">
        <image
          class="info-icon"
          src="/static/icon/activity_type_icon.png"
        />
        <text class="info-label">活动类型：</text>
        <text class="info-value">{{ info.activityTypeName }}</text>
      </view>
    </view>
    <view class="activity-divider"></view>
    <view class="activity-signup-row">
      <text class="signup-title">报名人员</text>
      <text class="signup-count"
        >{{
          info.registrationRecordList && info.registrationRecordList.length
        }}人已报名</text
      >
    </view>
    <scroll-view
      class="signup-list"
      scroll-x
      v-if="
        info.registrationRecordList && info.registrationRecordList.length > 0
      "
    >
      <view
        v-for="(user, idx) in info.registrationRecordList"
        :key="idx"
        class="signup-user"
      >
        <image
          class="signup-avatar"
          :src="formatImgUrl(user.avatar)"
        />
        <text class="signup-name">{{ formatName(user.nickName) }}</text>
      </view>
    </scroll-view>
    <view class="activity-divider"></view>
    <view class="activity-content-row">
      <text class="content-title">活动内容</text>
      <view class="content-text">
        <rich-text :nodes="processedContent"></rich-text>
      </view>
    </view>
    <view class="activity-footer-bar">
      <van-button
        class="footer-btn"
        type="primary"
        color="#0C8D6A"
        block
        round
        @click="$emit('signUp')"
        >我要报名</van-button
      >
    </view>
  </view>
</template>

<script>
  import RichTextUtils from '../../../common/richTextUtils.js'
  import { formatImgUrl } from '../../../common/utils.js'
  export default {
    name: 'ActivityDetailCard',
    props: {
      info: {
        type: Object,
        required: true
      }
    },
    computed: {
      processedContent() {
        return RichTextUtils.limitImageWidth(this.info.articleContent)
      }
    },
    methods: {
      formatName(name) {
        if (!name) return ''
        const arr = Array.from(name)
        const newName = arr.length > 3 ? arr.slice(0, 3).join('') + '...' : name
        return newName
      },
      formatImgUrl
    }
  }
</script>

<style scoped lang="scss">
  .activity-detail-card {
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
  }
  .activity-title {
    margin: 40rpx 0 0 0;
    font-size: 36rpx;
    font-weight: 600;
    color: #333;
    text-align: center;
  }
  .activity-publish {
    color: #666666;
    font-size: 24rpx;
    margin: 16rpx 0 0 0;
    text-align: center;
  }
  .activity-info-card {
    width: 686rpx;
    background: rgba(144, 165, 159, 0.1);
    border-radius: 15rpx;
    margin: 40rpx 32rpx 0 32rpx;
    display: flex;
    flex-direction: column;
    padding: 32rpx 20rpx;
    gap: 24rpx;
    box-sizing: border-box;
  }
  .info-row {
    display: flex;
    align-items: center;
    height: 48rpx;
  }
  .info-icon {
    width: 34rpx;
    height: 34rpx;
    margin-right: 12rpx;
  }
  .info-label {
    color: #666666;
    font-size: 26rpx;
    margin-right: 8rpx;
  }
  .info-value {
    color: #666666;
    font-size: 26rpx;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .activity-divider {
    width: 100vw;
    height: 16rpx;
    background: #f2f1f3;
    margin: 40rpx 0 0 0;
  }
  .activity-signup-row {
    width: 686rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin: 32rpx 0 0 0;
  }
  .signup-title {
    color: #333333;
    font-size: 32rpx;
    font-weight: 600;
  }
  .signup-count {
    color: #666666;
    font-size: 24rpx;
  }
  .signup-list {
    width: 686rpx;
    display: flex;
    flex-direction: row;
    margin: 24rpx 0 0 0;
    overflow-x: auto;
    white-space: nowrap;
  }
  .signup-user {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin-right: 32rpx;
  }
  .signup-avatar {
    width: 94rpx;
    height: 94rpx;
    border-radius: 50%;
    background: #eee;
  }
  .signup-name {
    color: #666666;
    font-size: 26rpx;
    margin-top: 8rpx;
    text-align: center;
  }
  .activity-content-row {
    width: 686rpx;
    margin: 32rpx 0 0 0;
    display: flex;
    flex-direction: column;
  }
  .content-title {
    color: #333333;
    font-size: 32rpx;
    font-weight: 600;
    margin-bottom: 16rpx;
  }
  .content-text {
    color: #666666;
    font-size: 28rpx;
    line-height: 1.8;
  }
  .activity-footer-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    padding: 24rpx 32rpx 32rpx 32rpx;
    box-shadow: 0rpx 7rpx 46rpx 0rpx rgba(0, 0, 0, 0.33);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .footer-btn {
    flex: 1;
    font-size: 32rpx;
    font-weight: 500;
    color: #fff;
    background: #0c8d6a;
    border-radius: 60rpx;
    border: none;
  }
</style>
